﻿/*
 * Copyright (c) 2011 Roberto García López
 * 
 * email: vcrobe@gmail.com
 * 
 * website: http://vcrobe.blogspot.com
 * 
 * project host: http://vectorGraphics.codeplex.com
 * 
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX;

namespace Ellipse
{
	public class ObjectBoundingRectangle
	{
		/// <summary>
		/// Represents the rectangle's Left, Bottom
		/// </summary>
		public Vector2 min;
		/// <summary>
		/// Represents the cube's Right, Top
		/// </summary>
		public Vector2 max;

		public ObjectBoundingRectangle(List<Vector2> vertices)
		{
			// By default the first vertex will be the bounding rectangle of the object
			min = vertices[0];
			max = vertices[0];
			// Compare all vertex
			for (int i = 1; i < vertices.Count; i++)
			{
				min = MathEx.Minimum(min, vertices[i]);
				max = MathEx.Maximum(max, vertices[i]);
			}
		}

		public ObjectBoundingRectangle(List<Vector3> vertices)
		{
			Vector3 mini, maxi;
			// By default the first vertex will be the bounding rectange of the object
			mini = vertices[0];
			maxi = vertices[0];
			// Compare all vertex
			for (int i = 1; i < vertices.Count; i++)
			{
				mini = MathEx.Minimum(mini, vertices[i]);
				maxi = MathEx.Maximum(maxi, vertices[i]);
			}

			min = new Vector2(mini.X, mini.Y);
			max = new Vector2(maxi.X, maxi.Y);
		}

		/// <summary>
		/// Merge the new bounding rectangle with this one resulting in a bounding rectangle containing both bounding rectangles
		/// </summary>
		/// <param name="bb"></param>
		public void Merge(ObjectBoundingRectangle br)
		{
			throw new NotImplementedException();
			//min = MathEx.Minimum(min, br.min);
			//max = MathEx.Maximum(max, br.max);
		}

		public override string ToString()
		{
			return string.Format("Min -> [ {0}, {1} ] Max -> [ {2}, {3} ]", min.X, min.Y, max.X, max.Y);
		}

	}
}
